$(function () {
    var getParams = getArgs();
    var currentHotel = getParams.hotel;
    var originalHref = $('.coupon-history').attr('href');
    var vipUserId = getParams.no;
    toastr.options = {
        "newestOnTop": false,
        "timeOut": 1500,
        "extendedTimeOut": 0,
        "escapeHtml": true,
        "positionClass": "toast-bottom-center"
    };
    if (currentHotel === undefined || currentHotel === '') {
        toastr.error(lang('toastr.grogshop'));
        return;
    }     
    var requestCard = function () {
        toggleLoading(true);
        ajaxRequest('/Home/Customer/getUserVipCardRecord', {
            "hotelId": currentHotel,
            "vipUserId":vipUserId
        }, 'post', function (data) {
            toggleLoading(false);
            var info = data.data;
            var cardHTML = '';
            if (info.length === 0) {
                cardHTML = $('#templateCardEmpty').clone().html();
            } else {
                $.each(info, function (key, value) {
                    var templatecardHTML = $($('#templateCardList').clone().html());
                    var handleType = ''
                    var changePrice = value.changePrice;
                    templatecardHTML.find('.neimenggu').text(value.price);
                    templatecardHTML.find('.card-record-time').text(value.updatetime);
                    templatecardHTML.find('.card-record-type').text(value.payType);
                    templatecardHTML.find('.card-record-channel').text(value.channel);
                    switch(parseInt(value.type)){
                        case 0:
                            if(parseFloat(value.changePrice)>0){
                                handleType = lang('member.01');
                            }else{
                                handleType = lang('member.02');
                                changePrice = (-parseFloat(value.changePrice)).toFixed(2);
                            } 
                            break;
                        case 1:    
                            handleType = lang('member.01');
                            break;
                        case 2:    
                            handleType = lang('member.02');
                            break;
                        case 3:    
                            handleType = lang('member.03');
                            break;                         
                    }    
                    templatecardHTML.find('.card-handle').text(handleType+changePrice);            
                    cardHTML += templatecardHTML.prop('outerHTML');
                });
            }
            $('#card-list').html(cardHTML);            
        }, function(error){
            toggleLoading(false); 
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });        
    }
    requestCard();
    $('#doc').on('click', '.card-refresh', function (e) {
        e.preventDefault();
        requestCard();
    });
});
